home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat31 / iobject / sources.lha / sources / Render.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-23  |  3.4 KB  |  195 lines

  1. // Routine sur les boites et borders V0.27
  2. // (C) 1992 Christophe PASSUELLO
  3. // Mon Jan 25 21:15:35 1993
  4.  
  5.  
  6. #include <mytypes.h>
  7. #include <exec/types.h>
  8. #define  INTUITION_PREFERENCES_H 0
  9. #include <graphics/rastport.h>
  10. #include <graphics/gfxmacros.h>
  11. #include "IObject_priv.h"
  12.  
  13.  
  14. UBYTE BackPen=0;
  15. UBYTE LightPen=2;
  16. UBYTE DarkPen=1;
  17. UBYTE Pen1=1;
  18. UBYTE Pen2=2;
  19.  
  20.  
  21. //
  22. // Initialise les couleurs
  23. //
  24. VOID SetIObjectColors(UBYTE back, UBYTE light, UBYTE dark, UBYTE pen1, UBYTE pen2)
  25. {
  26.     BackPen = back;
  27.     LightPen = light;
  28.     DarkPen = dark;
  29.     Pen1 = pen1;
  30.     Pen2 = pen2;
  31. }
  32.  
  33.  
  34. //
  35. // Dessine une boite en 3D en modifiant le DrawEnv
  36. //
  37. VOID FastDraw3DBox(struct Box *box, struct RastPort *rp, UWORD kind)
  38. {
  39.     // dessiner deux boites ?
  40.     if ((kind == BOX_2IN) || (kind == BOX_2OUT))
  41.     {
  42.         struct Box tmpbox;
  43.  
  44.         FastDraw3DBox(box, rp, (kind == BOX_2IN ? BOX_1IN : BOX_1OUT));
  45.  
  46.         tmpbox = *box;
  47.         tmpbox.x += 2;
  48.         tmpbox.y++;
  49.         tmpbox.w -= 4;
  50.         tmpbox.h -= 2;
  51.  
  52.         FastDraw3DBox(&tmpbox, rp, (kind == BOX_2IN ? BOX_1OUT : BOX_1IN));
  53.     }
  54.     else
  55.     {
  56.         // dessiner une boite
  57.         WORD x2, y2;
  58.  
  59.         x2 = box->x + box->w - 1;
  60.         y2 = box->y + box->h - 1;
  61.  
  62.         SetDrMd(rp, JAM1);
  63.     
  64.         /* dessine le light */
  65.         SetAPen(rp, (kind == BOX_1OUT ? LightPen : DarkPen));
  66.         Move(rp, x2, box->y);
  67.         Draw(rp, box->x, box->y);
  68.         Draw(rp, box->x, y2);
  69.         Move(rp, box->x + 1, box->y);
  70.         Draw(rp, box->x + 1, y2);
  71.  
  72.         /* dessine le dark */
  73.         SetAPen(rp, (kind == BOX_1OUT ? DarkPen : LightPen));
  74.         Move(rp, x2, box->y);
  75.         Draw(rp, x2, y2);
  76.         Draw(rp, box->x + 1, y2);
  77.         Move(rp, x2 - 1, box->y + 1);
  78.         Draw(rp, x2 - 1, y2);
  79.     }
  80. }
  81.  
  82.  
  83. //
  84. // Inverse une boite
  85. //
  86. VOID ComplementBox(struct Box *box, struct RastPort *rp)
  87. {
  88.     UBYTE drmd;
  89.  
  90.     drmd = rp->DrawMode;
  91.     SetDrMd(rp, COMPLEMENT);
  92.     RectFill(rp, box->x, box->y, box->x + box->w - 1, box->y + box->h - 1);
  93.     SetDrMd(rp, drmd);
  94. }
  95.  
  96. //
  97. // Dessine une boite en 3D
  98. //
  99. VOID Draw3DBox(struct Box *box, struct RastPort *rp, UWORD kind)
  100. {
  101.     struct DrawEnv env;
  102.  
  103.     SaveDrawEnv(rp, &env);
  104.     FastDraw3DBox(box, rp, kind);
  105.     RestoreDrawEnv(rp, &env);
  106. }
  107.  
  108.  
  109. //
  110. // Remplit une boite avec une couleur
  111. //
  112. VOID FastFillBox(struct Box *box, struct RastPort *rp, UBYTE coul)
  113. {
  114.     SetDrMd(rp, JAM1);
  115.     SetAPen(rp, coul);
  116.     RectFill(rp, box->x, box->y, box->x + box->w - 1, box->y + box->h - 1);
  117. }
  118.  
  119.  
  120. //
  121. // Remplit une boite avec une couleur
  122. //
  123. VOID FillBox(struct Box *box, struct RastPort *rp, UBYTE coul)
  124. {
  125.     struct DrawEnv env;
  126.  
  127.     SaveDrawEnv(rp, &env);
  128.     FastFillBox(box, rp, coul);
  129.     RestoreDrawEnv(rp, &env);
  130. }
  131.  
  132.  
  133. //
  134. // efface une boite avec la couleur coul en modifiant le DrawEnv
  135. //
  136. VOID FastEraseBox(struct Box *box, struct RastPort *rp)
  137. {
  138.     FastFillBox(box, rp, 0);
  139. }
  140.  
  141.  
  142. //
  143. // efface une boite avec la couleur coul
  144. //
  145. VOID EraseBox (struct Box *box, struct RastPort *rp)
  146. {
  147.     struct DrawEnv env;
  148.  
  149.     SaveDrawEnv(rp, &env);
  150.     FastEraseBox(box, rp);
  151.     RestoreDrawEnv(rp, &env);
  152. }
  153.  
  154.  
  155. //
  156. // Sauve l'environnement de dessin
  157. //
  158. VOID SaveDrawEnv(struct RastPort *rp, struct DrawEnv *env)
  159. {
  160.     env->APen = rp->FgPen;
  161.     env->BPen = rp->BgPen;
  162.     env->DrMd = rp->DrawMode;
  163. }
  164.  
  165.  
  166. //
  167. // Restaure l'environnement de dessin
  168. //
  169. VOID RestoreDrawEnv(struct RastPort *rp, struct DrawEnv *env)
  170. {
  171.     SetAPen(rp, env->APen);
  172.     SetBPen(rp, env->BPen);
  173.     SetDrMd(rp, env->DrMd);
  174. }
  175.  
  176.  
  177. //
  178. // Sauve l'environnement Texte
  179. //
  180. VOID SaveTextEnv(struct RastPort *rp, struct TextEnv *env)
  181. {
  182.     env->Font = rp->Font;
  183.     SaveDrawEnv(rp, &env->Env);
  184. }
  185.  
  186.  
  187. //
  188. // Restaure l'environnement texte
  189. //
  190. VOID RestoreTextEnv(struct RastPort *rp, struct TextEnv *env)
  191. {
  192.     RestoreDrawEnv(rp, &env->Env);
  193.     SetFont(rp, env->Font);
  194. }
  195.